#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
#include "proto.h"
#include <unistd.h>

int main(int argc, char *argv[])
{
	int sd;
	struct msg_st sbuf;
	struct sockaddr_in raddr;

	if (argc < 2) 
	{
		fprintf(stderr, "usage..\n");
		exit(1);
	}

	sd = socket(AF_INET, SOCK_DGRAM, 0);
	if (sd < 0)
	{
		perror("socket");
		exit(1);
	}

	//bind();
	strcpy(sbuf.name, "Alan");
	sbuf.math = htonl(99);
	sbuf.ch = htonl(93);

	raddr.sin_family = AF_INET;
	raddr.sin_port = htons(RCVPORT);
	inet_pton(AF_INET, argv[1], &raddr.sin_addr);

	if (sendto(sd, &sbuf, sizeof(sbuf), 0, (struct sockaddr *)&raddr, sizeof(raddr)) < 0)
	{
		perror("sendto");
		exit(1);
	}

	puts("ok\n");

	close(sd);

	exit(0);
}
